import 'package:flutter/material.dart';
import 'package:flutter/painting.dart';
import 'package:islandingclub/constants/image_constants.dart';
import 'package:islandingclub/screens/main_screen.dart';
import 'package:islandingclub/utils/screen_utils.dart';
import 'package:islandingclub/widgets/AnimatedLogo.dart';
import 'package:islandingclub/widgets/FadeRoute.dart';
import 'package:islandingclub/widgets/GrowTransition.dart';
import 'package:islandingclub/widgets/StaggerAnimation.dart';

class SplashScreen extends StatefulWidget {
  @override
  _SplashScreenState createState() => _SplashScreenState();
}

class _SplashScreenState extends State<SplashScreen>
    with SingleTickerProviderStateMixin {
  AnimationController _controller;

  @override
  void initState() {
    super.initState();
    // Future.delayed(Duration(seconds: 3), () {
    //   print("进入首页");
    // });

    _controller = AnimationController(
        duration: const Duration(milliseconds: 4500), vsync: this)
      ..addStatusListener((status) {
        if (status == AnimationStatus.completed) {
          // Navigator.of(context).pushReplacement(
          //     MaterialPageRoute(builder: (context) => MainScreen()));

          Navigator.of(context).pushReplacement(PageRouteBuilder(
            pageBuilder: (context, animation, secondaryAnimation) =>
                MainScreen(),
          ));

          // Navigator.of(context).pushReplacement(FadeRoute(
          //   builder: (context) => MainScreen(),
          // ));
        }
      });
    _controller.forward();
  }

  @override
  Widget build(BuildContext context) {
    // 初始化屏幕适配工具
    ScreenUtils.init(context);
    return Container(
      color: Colors.white,
      child: Center(
        child: AnimatedLogo(controller: _controller),
      ),
    );
  }

  @override
  void dispose() {
    _controller?.dispose();
    super.dispose();
  }
}

// class _SplashScreenState extends State<SplashScreen>
//     with TickerProviderStateMixin {
//   AnimationController _controller;
//
//   @override
//   void initState() {
//     super.initState();
//
//     _controller = AnimationController(
//         duration: const Duration(milliseconds: 2000), vsync: this);
//   }
//
//   Future<Null> _playAnimation() async {
//     try {
//       //先正向执行动画
//       await _controller.forward().orCancel;
//       //再反向执行动画
//       await _controller.reverse().orCancel;
//     } on TickerCanceled {
//       // the animation got canceled, probably because we were disposed
//     }
//   }
//
//   @override
//   Widget build(BuildContext context) {
//     return Scaffold(
//       backgroundColor: Colors.white,
//       body: GestureDetector(
//         behavior: HitTestBehavior.opaque,
//         onTap: () {
//           _playAnimation();
//         },
//         child: Center(
//           child: Container(
//             width: 300.0,
//             height: 300.0,
//             decoration: BoxDecoration(
//               color: Colors.black.withOpacity(0.1),
//               border: Border.all(
//                 color: Colors.black.withOpacity(0.5),
//               ),
//             ),
//             //调用我们定义的交织动画Widget
//             child: StaggerAnimation(controller: _controller),
//           ),
//         ),
//       ),
//     );
//   }
// }
